<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of gdesrianti
 *
 * @author Maulnick
 */
class gdesrianti extends CI_Controller{
    //put your code here
    public function __construct() {
        parent::__construct();
        $this->load->helper('url','form');
        $this->load->model('admins');
        $this->load->library('session');
    }
    public function index() {
        $data['title'] = 'contributor - login page';
        $data['content'] = $this->load->view('admin/login',$data,TRUE);
        $this->load->view('front',$data);
    }
    public function login(){
        $this->form_validation->set_rules('username','Username','required|trim|max_length[50]|xss_clean');
        $this->form_validation->set_rules('password','Password','required|trim|max_length[200]|xss_clean');
        if($this->form_validation->run()==false){
            $data['title'] = 'contributor - login page';
            $data['content'] = $this->load->view('admin/login',$data,TRUE);
            $this->load->view('front',$data);
        }else{
            $idadmin = $this->admins->validate();
            if(!$idadmin){
                echo "You are failed";
            }else{
                $data = array(
                    'idadmin' => $idadmin,
                    'is_logged_in' => true
                );
                //print_r ($data);
                $this->session->set_userdata('user',$data);
                //echo print_r ($this->session->userdata($data));
                //redirect('main');

                $data['title'] = 'home';
                $data['content'] = $this->load->view('page/home','',TRUE);
                $this->load->view('front',$data);
            }
        }
    }
    
    public function logout() {
        $this->session->sess_destroy();
        redirect();
    }
}

?>
